let fs = require("fs")
let path = require("path")
let fileHelp = require("./app/extend/fileHelp")


/** @param {import("egg").Application} app */
module.exports = function (app) {
	app.cache = {}// 挂载缓存
	app.logger.info(app.config.env)
	require("./app/valid/rule")(app)
	require("./app/util/relation")(app)
	let StaticCache = require("./app/static/staticCache")
	new StaticCache(app)
	autoCreate(app)
	// app.loader.loadFile(path.resolve("app.config.baseDir","app/definedValidate.js"))
}


/** 
 * 暂时失效
 * @param {import("egg").Application} app 
 * */
function watch(app) {
	fs.watch(path.join(app.baseDir, "/config/game.js"), (evt, fileName) => {
		app.logger.info(evt)
		let data = require(fileName) // 久对象
		require.cache[fileName] = undefined
		let d = require(fileName)
		for (const key in data) {
			if (d.hasOwnProperty(key)) {
				// const element = data[key];
				data[key] = d[key]
			}
			else {
				delete data[key]
			}
		}
	})
}
/** 
 * 暂时失效
 * @param {import("egg").Application} app 
 * */
function autoCreate(app) {
	fileHelp.dirExCreate(path.join(app.config.serverConfig.uploadPath, "/shf/"))
	fileHelp.dirExCreate(path.join(app.config.serverConfig.uploadPath, "/ad/"))
	fileHelp.dirExCreate(path.join(app.config.serverConfig.uploadPath, "/key/"))
}
